const express = require('express');
const user = require("./routes/user/api");
const admin = require("./routes/admin/api");
const computer = require("./routes/computer/api");
const food = require("./routes/food/api");
const drink = require("./routes/drink/api");
const consume = require("./routes/consume/api");

const app = express();
app.all("*", function (req, res, next) {
    //设置允许跨域的域名，*代表允许任意域名跨域
    res.header("Access-Control-Allow-Origin", "*");
    //允许的header类型
    res.header("Access-Control-Allow-Headers", "content-type");
    //跨域允许的请求方式 
    res.header("Access-Control-Allow-Methods", "DELETE,PUT,POST,GET,OPTIONS");
    if (req.method.toLowerCase() == 'options')
        res.send(200);  //让options尝试请求快速结束
    else
        next();
})
app.get("/",(req,res) => {
    res.send("error");
})
app.use("/api/user", user);
app.use("/api/admin", admin);
app.use("/api/computer", computer);
app.use("/api/food", food);
app.use("/api/drink", drink);
app.use("/api/consume", consume);
app.listen(3000, '0.0.0.0', function () {
    console.log('server start');
})
